﻿// Decompiled with JetBrains decompiler
// Type: UnityEngine.Rendering.ShadowSplitData
// Assembly: UnityEngine.CoreModule, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null
// MVID: E6AE6B5A-2752-4B07-9528-C8B77C62CE79
// Assembly location: C:\Users\windys\Unity\2021.3.39f1c1\Editor\Data\Managed\UnityEngine\UnityEngine.CoreModule.dll
// XML documentation location: C:\Users\windys\Unity\2021.3.39f1c1\Editor\Data\Managed\UnityEngine\UnityEngine.CoreModule.xml

using System;
using UnityEngine.Scripting;

#nullable disable
namespace UnityEngine.Rendering
{
  /// <summary>
  ///   <para>Describes the culling information for a given shadow split (e.g. directional cascade).</para>
  /// </summary>
  [UsedByNativeCode]
  public struct ShadowSplitData : IEquatable<ShadowSplitData>
  {
    private const int k_MaximumCullingPlaneCount = 10;
    /// <summary>
    ///   <para>The maximum number of culling planes.</para>
    /// </summary>
    public static readonly int maximumCullingPlaneCount = 10;
    private int m_CullingPlaneCount;
    internal unsafe fixed byte m_CullingPlanes[160];
    private Vector4 m_CullingSphere;
    private float m_ShadowCascadeBlendCullingFactor;
    private float m_CullingNearPlane;

    /// <summary>
    ///   <para>The number of culling planes.</para>
    /// </summary>
    public int cullingPlaneCount
    {
      get => this.m_CullingPlaneCount;
      set
      {
        this.m_CullingPlaneCount = value >= 0 && value <= 10 ? value : throw new ArgumentException(string.Format("Value should range from {0} to ShadowSplitData.maximumCullingPlaneCount ({1}), but was {2}.", (object) 0, (object) 10, (object) value));
      }
    }

    /// <summary>
    ///   <para>The culling sphere.  The first three components of the vector describe the sphere center, and the last component specifies the radius.</para>
    /// </summary>
    public Vector4 cullingSphere
    {
      get => this.m_CullingSphere;
      set => this.m_CullingSphere = value;
    }

    /// <summary>
    ///         <para>
    ///                     A multiplier applied to the radius of the culling sphere.
    /// 
    /// Values must be in the range 0 to 1. With higher values, Unity culls more objects. Lower makes the cascades share more rendered objects. Using lower values allows blending between different cascades as they then share objects.
    ///                 </para>
    ///       </summary>
    public float shadowCascadeBlendCullingFactor
    {
      get => this.m_ShadowCascadeBlendCullingFactor;
      set
      {
        this.m_ShadowCascadeBlendCullingFactor = (double) value >= 0.0 && (double) value <= 1.0 ? value : throw new ArgumentException(string.Format("Value should range from {0} to {1}, but was {2}.", (object) 0, (object) 1, (object) value));
      }
    }

    /// <summary>
    ///   <para>Gets a culling plane.</para>
    /// </summary>
    /// <param name="index">The culling plane index.</param>
    /// <returns>
    ///   <para>The culling plane.</para>
    /// </returns>
    public unsafe Plane GetCullingPlane(int index)
    {
      if (index < 0 || index >= this.cullingPlaneCount)
        throw new ArgumentException(nameof (index), string.Format("Index should be at least {0} and less than cullingPlaneCount ({1}), but was {2}.", (object) 0, (object) this.cullingPlaneCount, (object) index));
      fixed (byte* numPtr = this.m_CullingPlanes)
        return *(Plane*) (numPtr + ((IntPtr) index * sizeof (Plane)).ToInt64());
    }

    /// <summary>
    ///   <para>Sets a culling plane.</para>
    /// </summary>
    /// <param name="index">The index of the culling plane to set.</param>
    /// <param name="plane">The culling plane.</param>
    public unsafe void SetCullingPlane(int index, Plane plane)
    {
      if (index < 0 || index >= this.cullingPlaneCount)
        throw new ArgumentException(nameof (index), string.Format("Index should be at least {0} and less than cullingPlaneCount ({1}), but was {2}.", (object) 0, (object) this.cullingPlaneCount, (object) index));
      fixed (byte* numPtr = this.m_CullingPlanes)
        *(Plane*) (numPtr + ((IntPtr) index * sizeof (Plane)).ToInt64()) = plane;
    }

    public bool Equals(ShadowSplitData other)
    {
      if (this.m_CullingPlaneCount != other.m_CullingPlaneCount)
        return false;
      for (int index = 0; index < this.cullingPlaneCount; ++index)
      {
        if (!this.GetCullingPlane(index).Equals((object) other.GetCullingPlane(index)))
          return false;
      }
      return this.m_CullingSphere.Equals(other.m_CullingSphere);
    }

    public override bool Equals(object obj)
    {
      return obj != null && obj is ShadowSplitData other && this.Equals(other);
    }

    public override int GetHashCode()
    {
      return this.m_CullingPlaneCount * 397 ^ this.m_CullingSphere.GetHashCode();
    }

    public static bool operator ==(ShadowSplitData left, ShadowSplitData right)
    {
      return left.Equals(right);
    }

    public static bool operator !=(ShadowSplitData left, ShadowSplitData right)
    {
      return !left.Equals(right);
    }
  }
}
